﻿// <copyright file="FeatureCollection.cs" company="Signal Processing Lab, Wuhan University">
// Copyright (c) 2009-2010 All Right Reserved
// </copyright>
// <author>Xinping Deng</author>
// <email>dentoby@gmail.com</email>
// <date>2010-4</date>
// <summary>This is part of Image.NET project.</summary>

namespace SPLWHU.Core.Vectors
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    /// <summary>
    /// The collection of features.
    /// </summary>
    public class FeatureCollection : IEnumerable<Feature>
    {
        /// <summary>
        /// The shape provider.
        /// </summary>
        private IShapeProvider provider;

        /// <summary>
        /// Initializes a new instance of the <see cref="FeatureCollection"/> class by specifying a shape provider.
        /// </summary>
        /// <param name="provider">The shape provider.</param>
        public FeatureCollection(IShapeProvider provider)
        {
            this.provider = provider;
        }

        /// <summary>
        /// Gets or sets the shape provider.
        /// </summary>
        /// <value>The shape provider.</value>
        public IShapeProvider Provider
        {
            get { return this.provider; }
            set { this.provider = value; }
        }

        /// <summary>
        /// Gets the count of geometries in the collection.
        /// </summary>
        /// <value>The number of geometries.</value>
        public int Count
        {
            get { return this.provider.Count; }
        }

        /// <summary>
        /// Gets or sets the feature at the specified index.
        /// </summary>
        /// <param name="index">The index.</param>
        /// <returns>The geometry at the specified index.</returns>
        public Feature this[int index]
        {
            get { return this.provider[index]; }
            set { this.provider[index] = value; }
        }

        /// <summary>
        /// Adds a new feature to the collection.
        /// </summary>
        /// <param name="feature">The feature added.</param>
        public void Add(Feature feature)
        {
            this.provider.Add(feature);
        }

        /// <summary>
        /// Adds an array of features to the collection.
        /// </summary>
        /// <param name="features">The features added.</param>
        public void Add(Feature[] features)
        {
            this.provider.Add(features);
        }

        /// <summary>
        /// Adds a list of features to the collection.
        /// </summary>
        /// <param name="features">The features added.</param>
        public void Add(List<Feature> features)
        {
            this.provider.Add(features);
        }

        /// <summary>
        /// Removes the geometry at the specifed index.
        /// </summary>
        /// <param name="index">The index.</param>
        public void RemoveAt(int index)
        {
            this.provider.RemoveAt(index);
        }

        /// <summary>
        /// Removes the specified feature.
        /// </summary>
        /// <param name="feature">The feature removed.</param>
        public void Remove(Feature feature)
        {
            this.provider.Remove(feature);
        }

        /// <summary>
        /// Clears all features in this provider.
        /// </summary>
        public void Clear()
        {
            this.provider.Clear();
        }

        /// <summary>
        /// Gets the geometries within the bounding box.
        /// </summary>
        /// <param name="bbox">The bounding box.</param>
        /// <returns>A list of geometries.</returns>
        public List<Feature> GetFeatures(BoundingBox bbox)
        {
            return this.provider.GetFeatures(bbox);
        }

        /// <summary>
        /// Gets all the features.
        /// </summary>
        /// <returns>The features.</returns>
        public IEnumerable<Feature> GetFeatures()
        {
            return this.provider.GetFeatures();
        }

        #region IEnumerable<Feature> Members

        /// <summary>
        /// Gets the enumerator of all the features.
        /// </summary>
        /// <returns>
        /// The enumerator <see cref="T:System.Collections.Generic.IEnumerator`1"/> to access the features.
        /// </returns>
        public IEnumerator<Feature> GetEnumerator()
        {
            int cnt = this.Count;
            for (int i = 0; i < cnt; i++)
            {
                yield return this.provider[i];
            }
        }

        #endregion

        #region IEnumerable Members

        /// <summary>
        /// Gets the enumerator of all the features.
        /// </summary>
        /// <returns>
        /// The enumerator <see cref="T:System.Collections.IEnumerator"/> to access the features.
        /// </returns>
        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return this.GetEnumerator();
        }

        #endregion
    }
}
